package IF;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import sun.misc.BASE64Decoder;

import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author MJS
 * @Date 2021/10/8 18:13
 * @Description
 */
@Slf4j
public class TestIf {
    public static void main(String[] args) {
//        int[] prices = {1,2,3,4,6,8};
//        System.out.println(maxProfit(prices));
////        String a="马佳帅";
////        String nameLeng = a.length() > 2 ? a.substring(0, 2) : a.substring(0, 1);
////        System.out.println(nameLeng);
////        String a="2000-01-01 05:58:00";
////        System.out.println(a.subSequence(0, 10));
////        System.out.println(a.substring(11, 16));
////        List<String>list1 =new ArrayList<>();
////        boolean empty = list1.isEmpty();
////        System.out.println(empty);
////        String s = JSONObject.toJSONString(list1);
////        System.out.println(s);
////        List parse = (List) JSON.parse(s);
////        System.out.println(parse);
////        boolean empty1 = parse.isEmpty();
////        System.out.println(empty1);
////        System.out.println("-----------------------------");
////
////        List<String>list2 =new ArrayList<>();
////        list2.add("张三");
////        list2.add("李四");
////        list2.add("王五");
////        System.out.println(list2.isEmpty());
////        String s1 = JSONObject.toJSONString(list2);
////        System.out.println(s1);
////        List parse1 = (List) JSON.parse(s1);
////        System.out.println(parse1);
////        System.out.println(parse1.isEmpty());
//
////        list.add("张三");
////        list.add("李四");
////        list.add("王五");
////            String a ="[\"https://common-service-1302681310.cos.ap-beijing.myqcloud.com/common/loading_others/2021/4/27/56599a39-bb0a-49eb-9532-8044375f819b.jpg\",\"https://common-service-1302681310.cos.ap-beijing.myqcloud.com/common/loading_others/2021/4/27/56599a39-bb0a-49eb-9532-8044375f819b.jpg\"]";
////        JSONArray jsonObject =JSON.parseArray(a);
////        System.out.println(jsonObject.toJSONString());
////        System.out.println(Collections.EMPTY_LIST);
////        System.out.println(jsonObject);
////        String c ="哈哈哈";
////        JSONObject a =new JSONObject();
////        a.put("kkkk",1111);
////        System.out.println(a);
////        log.trace("--{}",a);
////        log.info("-----{}",a.toJSONString());
////        List<String>a =new ArrayList<>();
////        a.add("1");
////        a.add("2");
////        a.add("3");
////        a.add("4");
////        a.add("5");
////        System.out.println(a);
//        List<String>a=new ArrayList<>();
//        a.add("1");
//        a.add("2");
//        List<String>b=new ArrayList<>();
//        b.add("3");
//        b.add("4");
//        a.addAll(b);
//        System.out.println(a);
//        System.out.println(b);
//        List<String>c=new ArrayList<>();
////        b.add("1");
////        b.add("2");
////        b.add("3");
////        b.add("4");
////        b.add("5");
//
//
//        System.out.println(b);
//        System.out.println(a.removeAll(b));
//        System.out.println(a.size());


//        for (String s : parse) {
//            System.out.println(s);
//        }

//        long a =123132123123123L;
//        long b =1313131;
//        if(a>b) System.out.println("aaaa");;



                Integer i = 123456;
        while(txt2String(String.valueOf(i))){
           i= (int) ((Math.random() * 9 + 1) * 100000);
        }


    }

    public static Boolean txt2String(String a){
        boolean matches = Pattern.matches("(?:(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}|(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){5})\\d", a);
        boolean matches1 = Pattern.matches("^\\d*(\\d)\\1\\1(\\d)\\2\\2\\d*$", a);
        boolean matches2 = Pattern.matches("^(\\d)(\\d)(\\d)\\1\\2\\3$", a);
        boolean matches3 = Pattern.matches("^\\d*(\\d)\\1{2,}\\d*$", a);
        boolean matches4 = Pattern.matches("^(\\d)(\\d)\\2\\1\\2\\2$", a);
        return matches || matches1 || matches2 || matches3 || matches4;
    }


    public static int maxProfit(int[] prices) {
        if(prices==null || prices.length<2){
            return 0;
        }

        int sum = 0;
        for (int i = 1; i <prices.length; i++) {
            sum+=Math.max(0,prices[i]-prices[i-1]);
        }
        return sum;
        /*int minPrices = prices[0];//默认第一个值为最大值
        int maxPrices = prices[0];//默认第一个值为最小值
        int maxProfit;
        int sum=0;
        for(int i = 1; i < prices.length; i++){
            if(prices[i] < maxPrices){//如果当前价格小于最大价格
                maxProfit = maxPrices -minPrices;//利润等于最大价格减去最小价格
                sum+=maxProfit;//总利润
                minPrices = prices[i];//将当前值赋给最小值
                maxPrices = prices[i];//将当前值赋给最大值
            }else{//如果当前价格大于等于最大价格
                maxPrices = prices[i];//将当前值赋给最大值
                if(i == prices.length-1){//如果当前为最后一个值
                    sum+=(maxPrices - minPrices);//卖出股票，计算总利润
                }
            }
        }
        return sum;*/

    }

}
